package cc.yugu.yhdw.common.domain.basic;

import cc.yugu.yhdw.common.domain.LongIdEntity;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 微信模板消息
 *
 * @Date:Created in 2018/7/25 14:51
 * @Author:
 * @Modified By: zjn 2018/7/25 14:51
 */
public class WeixinTemplateMessage extends LongIdEntity {
    public static final int DELAY_TIME_ZERO = 0;
    public static final int DELAY_THIRTY_SECOND = 30;

    public static final int MAX_RESEND_NUM = 1;

    public enum MessageStatus {
        NOT(1, "未发"),
        OK(2, "成功"),
        FAIL(3, "失败"),
        ;

        private final int value;
        private final String name;

        private MessageStatus(int value, String name) {
            this.value = value;
            this.name = name;
        }

        private static Map<Integer, String> map = new HashMap<Integer, String>();
        static {
            for (MessageStatus e : MessageStatus.values()) {
                map.put(e.getValue(), e.getName());
            }
        }

        public static String getName(int value) {
            return map.get(value);
        }

        public int getValue() {
            return value;
        }

        public String getName() {
            return name;
        }
    }

    public enum SourceType {
        SEND_ORDER(1, "寄件订单"),
        DELIVER_ORDER(2, "派件订单"),
        STORE_ORDER(3, "存包订单"),
        WITHDRAWAL(4, "提现"),
        DEPOSIT(5, "充值"),
        AUTH_CODE(6, "验证码")
        ;

        private final int value;
        private final String name;

        private SourceType(int value, String name) {
            this.value = value;
            this.name = name;
        }

        public int getValue() {
            return value;
        }

        public String getName() {
            return name;
        }

        public static String getSourceTypeName(int value) {
            String rtn = null;
            for (SourceType e : SourceType.values()) {
                if (e.getValue() == value) {
                    rtn = e.getName();
                    break;
                }
            }
            return rtn;
        }
    }

    public enum Type {
        DELIVER_NOTICE(1, "派件通知"),
        DELIVER_TIMEOUT_NOTICE(2, "派件超时通知"),
        ;

        private final int value;
        private final String name;

        private Type(int value, String name) {
            this.value = value;
            this.name = name;
        }

        public int getValue() {
            return value;
        }

        public String getName() {
            return name;
        }
    }

    public static String buildVariableJson(String[] variable) {
        StringBuilder builder = new StringBuilder();
        if(variable.length % 2 != 0) {
            throw new IllegalArgumentException();
        }

        builder.append("{");
        for(int i = 0; i < variable.length; i = i + 2) {
            builder.append("\"");
            builder.append(variable[i]);
            builder.append("\":");
            builder.append("\"");
            builder.append(variable[i + 1]);
            builder.append("\"");

            if(i < variable.length - 2) {
                builder.append(",");
            }
        }
        builder.append("}");
        return builder.toString();
    }

    Integer agentId; //运营商id
    String sourceId; //来源类型的id
    Integer sourceType; //来源类型
    String mobile; //手机号
    String openId;//openid
    Date handleTime;//处理时间
    Date createTime;//创建模板消息时间
    Integer status;
    Integer type; //短信类型
    Integer delay; //延迟times发送
    Integer resendNum; //重发
    String variable; //变量

    public Integer getAgentId() {
        return agentId;
    }

    public void setAgentId(Integer agentId) {
        this.agentId = agentId;
    }

    public String getSourceId() {
        return sourceId;
    }

    public void setSourceId(String sourceId) {
        this.sourceId = sourceId;
    }

    public Integer getSourceType() {
        return sourceType;
    }

    public void setSourceType(Integer sourceType) {
        this.sourceType = sourceType;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getOpenId() {
        return openId;
    }

    public void setOpenId(String openId) {
        this.openId = openId;
    }

    public Date getHandleTime() {
        return handleTime;
    }

    public void setHandleTime(Date handleTime) {
        this.handleTime = handleTime;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public Integer getDelay() {
        return delay;
    }

    public void setDelay(Integer delay) {
        this.delay = delay;
    }

    public Integer getResendNum() {
        return resendNum;
    }

    public void setResendNum(Integer resendNum) {
        this.resendNum = resendNum;
    }

    public String getVariable() {
        return variable;
    }

    public void setVariable(String variable) {
        this.variable = variable;
    }
}
